package com.tsd.system.service.impl;

import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.service.BaseServiceImpl;
import com.tsd.system.dao.SysLoginInfoMapper;
import com.tsd.system.entity.SysLoginInfo;
import com.tsd.system.entity.SysLoginInfoExt;
import com.tsd.system.entity.SysUser;
import com.tsd.system.service.SysLoginInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述：SysLoginInfo 服务实现层
 *
 * @author Luoyc
 * @date 2020/05/15 15:39:42
 */
@Service
public class SysLoginInfoServiceImpl extends BaseServiceImpl implements SysLoginInfoService {

    @Resource
    private SysLoginInfoMapper sysLoginInfoMapper;

    @Override
    public SysLoginInfo getSysLoginInfoById(Long id) throws Exception {
        return sysLoginInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public SysLoginInfoExt queryBySid(String sid) throws Exception {
        return sysLoginInfoMapper.selectBySid(sid);
    }

    @Override
    public void deleteSysLoginInfo(Long id, SysUser opUser) throws Exception {
        SysLoginInfo old = sysLoginInfoMapper.selectByPrimaryKey(id);
        super.checkEmpty(old, "该记录不存在");
        super.autoInjectBaseData(old, opUser, this.TYPE_DELETE);
        sysLoginInfoMapper.updateByPrimaryKeySelective(old);
    }

    @Override
    public void saveSysLoginInfo(SysLoginInfo record, SysUser opUser) throws Exception {
        if (HlpUtils.isEmpty(record.getId())) {
            super.autoInjectBaseData(record, opUser, this.TYPE_CREATE);
            sysLoginInfoMapper.insertSelective(record);
        } else {
            super.autoInjectBaseData(record, opUser, this.TYPE_UPDATE);
            sysLoginInfoMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public List<SysLoginInfoExt> findSysLoginInfos(Map<String, Object> params, PageBean page) throws Exception {
        return sysLoginInfoMapper.selectByPage(params, page);
    }

    @Override
    public List<SysLoginInfoExt> findSysLoginInfos(Map<String, Object> params) throws Exception {
        return sysLoginInfoMapper.selectByParams(params);
    }
}
